//
//  LSFunctionListViewController.m
//  KuaiYi
//
//  Created by ZengFanSheng on 2016/11/13.
//  Copyright © 2016年 HeiMa. All rights reserved.
//

#import "LSFunctionListViewController.h"
#import "LSFunctionModel.h"
#import <YYModel.h>

static NSString *functionCellIdentifier = @"functionCellIdentifier";
@interface LSFunctionListViewController () 


@end

@implementation LSFunctionListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)setupUI
{
    [super setupUI];
    
    UITableView *tb = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    [self.view addSubview:tb];
    tb.dataSource = self;
    
    _tableView = tb;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _dataList.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *groupArr = _dataList[section];
    return groupArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:functionCellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:functionCellIdentifier];
    }
    
    NSArray *groupArr = _dataList[indexPath.section];
    LSFunctionModel *model = groupArr[indexPath.row];
    
    cell.textLabel.text = model.name;
    
    if (model.icon != nil) {
        cell.imageView.image = [UIImage imageNamed:model.icon];
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    if (model.detail != nil) {
        cell.detailTextLabel.text = model.detail;
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return cell;
}

- (void)loadDataPlistWithName:(NSString *)plistName
{
    NSURL *url = [[NSBundle mainBundle] URLForResource:plistName withExtension:nil];
    NSArray *plistArr = [NSArray arrayWithContentsOfURL:url];
    NSMutableArray *arrayM = [NSMutableArray array];
    for (NSArray *groupArr in plistArr) {
        NSMutableArray *groupArrayM = [NSMutableArray array];
        for (NSDictionary *dict in groupArr) {
            LSFunctionModel *model = [[LSFunctionModel alloc] init];
            [model setValuesForKeysWithDictionary:dict];
            [groupArrayM addObject:model];
        }
        [arrayM addObject:groupArrayM];
    }
    
    _dataList = arrayM;
    
    [_tableView reloadData];
    NSLog(@"%@",arrayM);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
